local Mongo = require "core.Mongo"
local PlayerMongo = Mongo.players

local M = {}

function M.getPlayerByUuid(_id)
    return PlayerMongo:findOne({
        _id = _id
    })
end

function M.getPlayer(playerId, keys)
    return PlayerMongo:findOne({
        id = playerId
    }, keys)
end

function M.incrementCoin(playerId, coin)
    PlayerMongo:updateOne({
        id = playerId
    }, {
        ['$inc'] = {
            coin = coin
        }
    })
end

function M.decrementCoin(playerId, coin)
    M.incrementCoin(playerId, -coin)
end

function M.isPlayerExists(playerId)
    return M.getPlayer(playerId) ~= nil
end

function M.createPlayer(data)
    PlayerMongo:insertOne(data)
end

return M
